package com.larry.mr.mapjoin;

import com.larry.mr.reducejoin.OrderPd;
import com.larry.mr.reducejoin.ReduceJoinDriver;
import com.larry.mr.reducejoin.ReduceJoinMapper;
import com.larry.mr.reducejoin.ReduceJoinReducer;
import org.apache.hadoop.conf.Configuration;
import org.apache.hadoop.fs.Path;
import org.apache.hadoop.io.NullWritable;
import org.apache.hadoop.io.Text;
import org.apache.hadoop.mapreduce.Job;
import org.apache.hadoop.mapreduce.lib.input.FileInputFormat;
import org.apache.hadoop.mapreduce.lib.output.FileOutputFormat;

import java.io.IOException;
import java.net.URI;

/**
 * @ProjectName hadoop
 * @Author larry
 * @Date 17:01 2021/11/16
 * @Description TODO
 **/
public class MapJoinDriver {
    public static void main(String[] args) throws IOException, InterruptedException, ClassNotFoundException {
        Configuration configuration = new Configuration();
        Job job = Job.getInstance(configuration);

        //启动类
        job.setJarByClass(MapJoinDriver.class);

        //mapper    reducer
        job.setMapperClass(MapJoinMapper.class);

        //map输出键值类型
        job.setMapOutputKeyClass(Text.class);
        job.setMapOutputValueClass(NullWritable.class);

        //最终输出类型
        job.setOutputKeyClass(Text.class);
        job.setOutputValueClass(NullWritable.class);

        job.setNumReduceTasks(0);

        //设置缓存文件路径
        job.addCacheFile(URI.create("file:///C:/Users/larry/IdeaProjects/hadoop/MapReduce/src/main/resources/reducejoin/pd.txt"));

        //输入输出
        FileInputFormat.setInputPaths(job,new Path("C:\\Users\\larry\\IdeaProjects\\hadoop\\MapReduce\\src\\main\\resources\\mapjoin\\order.txt"));
        FileOutputFormat.setOutputPath(job,new Path("C:\\Users\\larry\\IdeaProjects\\hadoop\\MapReduce\\src\\main\\resources\\mapjoin\\out1"));

        boolean flag = job.waitForCompletion(true);

        System.exit(flag ? 0 : 1);
    }
}
